/*
 * Copyright(C) 2010 the original author or authors.
 *
 * Change History Log
 * ----------------------------------------------------
 * Version: 1.0
 * Date: 2011-5-22
 * Author: wangzl
 * ----------------------------------------------------
 */
package com.seemsea.entity.admin.coupon;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.seemsea.dao.IGenericEntity;
import com.seemsea.entity.admin.BaseEntity;

/**
 * 
 * 
 * @author wangzl
 * @since 2011-5-22
 */
@Entity
@Table(name="coupon_coupon")
public class Coupon  extends BaseEntity implements IGenericEntity<String>{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6895689474306189380L;
	@Id
	private String code;
	private String name;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "product_id")
	private Product product;
	private Date startDate;
	private Date endDate;
	private int ifactive;//是否有效
	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable=false,nullable=false)
	private Date createTime;
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;
	@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "coupon", fetch = FetchType.LAZY)
	private List<CouponItem> couponItems;
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Product getProduct() {
		if(product == null) product = new Product();
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public int getIfactive() {
		return ifactive;
	}
	public void setIfactive(int ifactive) {
		this.ifactive = ifactive;
	}
	public Date getCreateTime() {
		if(createTime == null){
			createTime = new Date();
		}
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	public List<CouponItem> getCouponItems() {
		return couponItems;
	}
	public void setCouponItems(List<CouponItem> couponItems) {
		this.couponItems = couponItems;
	}
}
